
//
//  LeftHeadView.m
//  lisure0.1
//
//  Created by xalo on 16/4/23.
//  Copyright © 2016年 Mr.wangYongxu. All rights reserved.
//

#import "LeftHeadView.h"


@implementation LeftHeadView


-(UIButton*)createButtonwith:(NSString*)title{
    //创建收藏按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];

    return button;

}

-(void)creatLayout{

    __weak LeftHeadView* weakSelf = self;
//    CGFloat width = [self frame].size.width;
    CGFloat height = [self frame].size.height;
    NSLog(@"height%.2f",height);
    self.imageView = [[UIImageView alloc]init];
    self.imageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.imageView];
    self.collectionBtn = [self createButtonwith:@"已收藏"];
    self.collectionBtn.tag = 1500;
    [self addSubview:self.collectionBtn];
    self.downLoadBtn = [self createButtonwith:@"已下载"];
    self.downLoadBtn.tag = 1501;
    [self addSubview:self.downLoadBtn];
    [self.collectionBtn addTarget:self action:@selector(actionTo:) forControlEvents:UIControlEventTouchUpInside];
    [self.downLoadBtn addTarget:self action:@selector(actionTo:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make){

        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.left.equalTo(weakSelf.mas_left).with.offset(20);
        make.width.and.height.equalTo(weakSelf.mas_height).multipliedBy(1.0/2.0);
    }];

//    NSLog(@"%@",NSStringFromCGRect(self.imageView.frame));

    [self.collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_top).with.offset(0);
        make.left.equalTo(weakSelf.mas_left).with.offset(20+height/2);
        make.height.equalTo(weakSelf.mas_height).multipliedBy(1.0/4.0);
        make.width.equalTo(weakSelf.mas_height).multipliedBy(1.0/2.0);
    }];
    [self.downLoadBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.collectionBtn.mas_bottom);
        make.left.equalTo(self.collectionBtn.mas_left);
        make.size.equalTo(self.collectionBtn);
    }];
}


-(void)actionTo:(UIButton*)sender{

    if (self.clickBtn) {
        self.clickBtn(sender);
    }


}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
